package com.mokairui.design.creatormodel.singleton.demo2;

/**
 * @Program: basic-summary
 * @Description: 懒汉式
 * @Author Mokairui
 * @Date 2021/5/30 21:37
 */
public class Singleton2 {
    private Singleton2() {}
    private static Singleton2 instance;

    public static synchronized Singleton2 getInstance() {
        if (instance == null) {
            // 如果是多线程，可能会破坏单例,可以在方法上用同步synchronized进行修饰为同步方法
            instance = new Singleton2();
        }
        return instance;
    }
}
